function* gFunc() {
  let _rst = 0;
  _rst = yield Promise.resolve(_rst);
  console.log("_rst1", _rst);
  _rst = yield Promise.resolve(_rst + 1);
  console.log("_rst2", _rst);
  _rst = yield Promise.resolve(_rst + 1);
  console.log("_rst3", _rst);
}

// 执行生成器函数
function execGfn(fn) {
  let g = fn();

  return new Promise((resolve, reject) => {
    function nextStep(_next) {
      let { value, done } = _next;

      if (done) return resolve(value);

      // 使用Promise.resolve增加容错
      Promise.resolve(value)
        .then((res) => {
          // 值要传进去
          nextStep(g.next(res));
        })
        .catch((err) => {
          reject(err);
        });
    }
    nextStep(g.next());
  });
}

execGfn(gFunc);
